/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package presentation.view;

import logic.facade.StudentFacade;
import javax.swing.JOptionPane;
import presentation.controller.ControlPanelMyAccount;
import vo.StudentVO;

/**
 *
 * @author Joanna 8a
 */
public class PanelMyAccount extends javax.swing.JPanel {

    /**
     * Creates new form PanelMyAccount
     * @param camposEditables Cuando entra en las Opciones de ver cuenta o eliminar cuenta es false, si es Modificar es true
     * @param opcion La opcion de manejo de cuenta: ver, modificar o eliminar.
     */
    public PanelMyAccount(boolean camposEditables, String opcion, MainFrame fp, AuxiliarFrame aux) {
        this.parent = fp;
        this.aux = aux;
        
        initComponents();  
        StudentVO alumno = new ControlPanelMyAccount().findByIp();
        jTextFieldNameAccount.setEditable(camposEditables); 
        jTextFieldNameAccount.setText(alumno.getName());
        jTextFieldLastNameAccount.setEditable(camposEditables);
        jTextFieldLastNameAccount.setText(alumno.getLastName());
        jTextFieldCareerAccount.setEditable(camposEditables);
        jTextFieldCareerAccount.setText(alumno.getCareer());
        //setBorder(javax.swing.BorderFactory.createTitledBorder(null, opcion, javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 1, 14), new java.awt.Color(0, 102, 102)));
        jButtonSave.setText(opcion);
        if (opcion.equals("Ver Cuenta")){
            parent.setIconImage(new javax.swing.ImageIcon(getClass().getResource("/presentation/view/images/Smiley1.png")).getImage());
            jButtonSave.setVisible(false);
        }
        
       
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelNameAccount = new javax.swing.JLabel();
        jLabellastNameAccount = new javax.swing.JLabel();
        jLabelCareerAccount = new javax.swing.JLabel();
        jTextFieldNameAccount = new javax.swing.JTextField();
        jTextFieldLastNameAccount = new javax.swing.JTextField();
        jTextFieldCareerAccount = new javax.swing.JTextField();
        jButtonSave = new javax.swing.JButton();
        jButtonBack = new javax.swing.JButton();

        setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Mi Cuenta", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 1, 14), new java.awt.Color(0, 102, 102))); // NOI18N

        jLabelNameAccount.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        jLabelNameAccount.setText("Nombre");

        jLabellastNameAccount.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        jLabellastNameAccount.setText("Apellidos");

        jLabelCareerAccount.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        jLabelCareerAccount.setText("Carrera");

        jTextFieldNameAccount.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        jTextFieldNameAccount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldNameAccountActionPerformed(evt);
            }
        });

        jTextFieldLastNameAccount.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        jTextFieldLastNameAccount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldLastNameAccountActionPerformed(evt);
            }
        });

        jTextFieldCareerAccount.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        jTextFieldCareerAccount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldCareerAccountActionPerformed(evt);
            }
        });

        jButtonSave.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        jButtonSave.setText("Guardar");
        jButtonSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSaveActionPerformed(evt);
            }
        });

        jButtonBack.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        jButtonBack.setText("Volver");
        jButtonBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBackActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelNameAccount)
                            .addComponent(jLabellastNameAccount)
                            .addComponent(jLabelCareerAccount))
                        .addGap(76, 76, 76)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldNameAccount)
                            .addComponent(jTextFieldLastNameAccount)
                            .addComponent(jTextFieldCareerAccount, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(81, 81, 81)
                        .addComponent(jButtonSave)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonBack)))
                .addContainerGap(26, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNameAccount)
                    .addComponent(jTextFieldNameAccount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabellastNameAccount)
                    .addComponent(jTextFieldLastNameAccount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelCareerAccount)
                    .addComponent(jTextFieldCareerAccount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonSave)
                    .addComponent(jButtonBack))
                .addContainerGap(15, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jTextFieldNameAccountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldNameAccountActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldNameAccountActionPerformed

    private void jTextFieldLastNameAccountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldLastNameAccountActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldLastNameAccountActionPerformed

    private void jTextFieldCareerAccountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldCareerAccountActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldCareerAccountActionPerformed

    private void jButtonBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBackActionPerformed
        aux.dispose();
    }//GEN-LAST:event_jButtonBackActionPerformed

    private void jButtonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveActionPerformed
        eliminarCuenta();
    }//GEN-LAST:event_jButtonSaveActionPerformed

    private void eliminarCuenta(){
        vo.StudentVO elim = new ControlPanelMyAccount().findByIp();
        parent.setIconImage(new javax.swing.ImageIcon(getClass().getResource("/presentation/view/images/Smiley2.png")).getImage());
        if(new StudentFacade().delete(elim.getUsername())){
            JOptionPane.showMessageDialog(this, "El Usuario ha sido eliminado exitosamente!", "Aviso", JOptionPane.INFORMATION_MESSAGE);
            parent.cambiarPanel(new PanelLogin(parent));
            parent.controlBarraHerramientas(false, false);
            
        }
        else{
            JOptionPane.showMessageDialog(this, "No se ha podido eliminar el Usuario.\n "
                                                + "Por favor intente mas tarde", "Error", JOptionPane.INFORMATION_MESSAGE);
            aux.dispose();
        }
    }
    
    private AuxiliarFrame aux;
    private MainFrame parent;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonBack;
    private javax.swing.JButton jButtonSave;
    private javax.swing.JLabel jLabelCareerAccount;
    private javax.swing.JLabel jLabelNameAccount;
    private javax.swing.JLabel jLabellastNameAccount;
    private javax.swing.JTextField jTextFieldCareerAccount;
    private javax.swing.JTextField jTextFieldLastNameAccount;
    private javax.swing.JTextField jTextFieldNameAccount;
    // End of variables declaration//GEN-END:variables
}
